{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 13.1 KMeans算法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 13.1.2 KMeans算法的简单代码实现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.构造数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "data = np.array([[3, 2], [4, 1], [3, 6], [4, 7], [3, 9], [6, 8], [6, 6], [7, 7]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 2],\n",
       "       [4, 1],\n",
       "       [3, 6],\n",
       "       [4, 7],\n",
       "       [3, 9],\n",
       "       [6, 8],\n",
       "       [6, 6],\n",
       "       [7, 7]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.可视化展示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAFIxJREFUeJzt3X+QXWV9x/HPZ0kkXsoPJ1ltSrJZmAYMJBDD5VcjqCCMAhOmFqcwSYuMdCljKzBFhMGpwpgZHTs1tjh0blFJyzVgIzDIIAMYrMTh1waC5AdalGxYg7JEfrhsQ4l8+8e5Cclykz03e8+990ner5k7Z8+5z5773Sd7Pjn7nHPv44gQACAdXe0uAADQGIIbABJDcANAYghuAEgMwQ0AiS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1o692cIHqD5NILeirdt1VMlXS0tpV2S5J34uIu21fL6k/Iu5SdlHiP20/q+zM8fwOqeuzthdI2lqr61MtqKuuDuivPHW1o7/eJ+mO2jE9QdJ3I+Je238rSRHxb5LukXSWpGcljUi6qEPqOk/Spba3SvpfSecX/R9wzd9LqtaGAH4l6aIO6K+xampLX9kuSTpD0iU7bGtpX/HOSQBITNvHuAEAjSG4ASAxBDcAJIbgBoDEENwAkBiCGwASQ3ADQGIIbgBIzP8DM7wgtiEuiokAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(data[:, 0], data[:, 1], c=\"red\", marker='o', label='samples')  # 以红色圆圈样式绘制散点图并加上标签\n",
    "plt.legend()  # 设置图例，图例内容为上面设置的label参数\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plt.scatter?  # 如果想查看scatter的官方说明，可以在其plt.scatter后面加上?进行查看"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.KMeans聚类（聚类成2类）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "    n_clusters=2, n_init=10, n_jobs=None, precompute_distances='auto',\n",
       "    random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "kms = KMeans(n_clusters=2)\n",
    "kms.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# KMeans?  # 如果想查看KMeans的官方说明，可以在其KMeans后面加上?进行查看"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.获取结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 1 1 1 1 1 1]\n"
     ]
    }
   ],
   "source": [
    "label = kms.labels_\n",
    "print(label)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.结果可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1b24d7d09e8>"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAFo1JREFUeJzt3X9wVeWdx/H3N3AVCFYWiPFHDBFxkPIj0V6glJGK1FJbJ51Fp4uglto2uzvuqtsdOt2hoxKKozPOTl3t1InYWteAglZLBWndYd22MysSFJTwY6g/IEEXY6z8aAoG+O4f94IhvZhzyT333od8XjOZe+85D+d852nPx3Ofc+55zN0REZFwlBS6ABERyY6CW0QkMApuEZHAKLhFRAKj4BYRCYyCW0QkMApuEZHAKLhFRAKj4BYRCUz/ODY6fPhwr6qqimPTIiKnpQ0bNnzg7mVR2sYS3FVVVTQ1NcWxaRGR05KZ7YzaVkMlIiKBUXCLiARGwS0iEphYxrhFRLrr7OyktbWVgwcPFrqUghowYAAVFRUkEolT3oaCW0TyorW1lbPOOouqqirMrNDlFIS7097eTmtrKxdddNEpbyfSUImZ3W5mm82s2czuOOW9iUifdfDgQYYNG9Zn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q7pcBfwZ+0K1NvvsrSk2F6CsA0kM3tcCKTKszLMtpXxX8rpL015+XgK90W9UKXAhgZv2Bs4EPC12Xu7e7+6H0x0eAz+WhnKlArZm9AzwJXGVmT3RrU4j+6rGuAvUX7v5u+vV9UmOQk7o1Od5faRXAu4Wuy933HRuuc/fVQMLMhsdcVivQ2uXb5dOkQrN7m3z2V481FaivjrkGeNXd92RYF3tfFequkjIzG5J+PxD4ErCtW7OVwDfT768H1nrMN51HqavbWFUtqYtysXL3f3P3CnevIvX1bK2739itWd77K0pdhegvMys1s7OOvQe+DGzu1mwlcHP6DoDPA3vd/b1C12Vm5x67NmFmk0gdo+1x1uXu/we0mNno9KIZwJZuzfLaX1FqKkRfdXEDmYdJIA99Vai7Ss4DfpG+KlsCLHf3582sHmhy95WkLkr8p5n9kdSZ4+wiqes2M6sFDqfrmpeHujIqgv6KUlch+qsceDZ9TPcHlrr7GjP7BwB3fxhYDXwV+CPQAXyrSOq6HvhHMzsM/AWYHfd/gNP+GWhMDwG8BXyrCPqrp5oK0ldmNgi4Gvj7Lsvy2lf65aSISGAKPsYtIiLZUXCLiARGwS0iEhgFt4hIYBTcIiKBUXCLiARGwS0iEhgFt4hIYP4flnSfQif+kXwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(data[label == 0][:, 0], data[label == 0][:, 1], c=\"red\", marker='o', label='class0')  # 以红色圆圈样式绘制散点图并加上标签\n",
    "plt.scatter(data[label == 1][:, 0], data[label == 1][:, 1], c=\"green\", marker='*', label='class1')  # 以绿色星星样式绘制散点图并加上标签\n",
    "plt.legend()  # 设置图例"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6.聚类成3类，并可视化呈现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 1 0 0 0 2 2 2]\n"
     ]
    }
   ],
   "source": [
    "kms_3 = KMeans(n_clusters=3)\n",
    "kms_3.fit(data)\n",
    "label_3 = kms_3.labels_\n",
    "print(label_3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1b24d843f60>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAF6lJREFUeJzt3X9w1fW95/HnGzguJvHHAjEiMYmIY1PARAxQlimSpl5ab4dOweliaJHa3dzdca/a7nhn79LVEgqDM+2M3rVzO6h7+4NcFfRKsShtd1i9286IBAUloJNKwYTeizFeAyyXNuJ7/zgnGI4n5HvI+Z5zPuT1mMmck+/3k+/3zUd4+cnnfL+fr7k7IiISjjGFLkBERLKj4BYRCYyCW0QkMApuEZHAKLhFRAKj4BYRCYyCW0QkMApuEZHAKLhFRAIzLo6DTpo0yWtqauI4tIjIBWn37t3vuXt5lLaxBHdNTQ3t7e1xHFpE5IJkZoejttVUiYhIYBTcIiKBUXCLiAQmljluEZF0/f39dHd3c+rUqUKXUlDjx4+nsrKSRCJx3sdQcItIXnR3d3PJJZdQU1ODmRW6nIJwd3p7e+nu7uaaa6457+NEmioxs3vMbJ+ZdZjZved9NhEZtU6dOsXEiRNHbWgDmBkTJ04c8W8dwwa3mc0A/iMwB6gDvmRm143orENpa4OaGhgzJvna1hbLaUSkMEZzaA/IRR9EGXHXAi+7+0l3/xB4CfjKiM+crq0NWlrg8GFwT762tCi8RUTSRAnufcACM5toZiXArcDVOa9k1So4efLsbSdPJreLiMTku9/9Lt///vdzdrzt27dz/fXXM23aNNavX5+z4w42bHC7+wHgQeDXwHZgL/BhejszazGzdjNr7+npyb6Sd97JbruISJE5ffo0d911Fy+88AL79+/niSeeYP/+/Tk/T6QPJ939cXef5e4LgPeBzgxtNrh7g7s3lJdHut3+bFVV2W0XkQtbTJ95/fSnP+WGG26grq6Or3/962fte/TRR5k9ezZ1dXUsXbqUk6lZgM2bNzNjxgzq6upYsGABAB0dHcyZM4f6+npuuOEGOjs7eeWVV5g2bRpTp07loosuYtmyZfz85z/PSd2DRb2q5IrUaxWwBHgi55WsXQslJWdvKylJbheR0SWmz7w6OjpYu3YtO3bsYO/evTz88MNn7V+yZAm7du1i79691NbW8vjjjwPQ2trKL3/5S/bu3cvWrVsB+NGPfsQ999zDnj17aG9vp7KykiNHjnD11R/PJA9sy7Wod04+Y2b7geeAu9z9X3JeyfLlsGEDVFeDWfJ1w4bkdhEZXWL6zGvHjh3cdtttTJo0CYAJEyactX/fvn189rOfZebMmbS1tdHR0QHA/PnzWblyJY8++iinT58GYN68eaxbt44HH3yQw4cPc/HFF+PunzhnHFfSRLoBx90/m/MzZ7J8uYJaRGL7zMvdzxmkK1euZMuWLdTV1fHjH/+YF198EUiOrnfu3Mm2bduor69nz549NDc3M3fuXLZt28aiRYt47LHHqKyspKur68zxuru7ueqqq0ZUcyZaq0REik9Mn3k1NTWxadMment7AXj//ffP2n/8+HEmT55Mf38/bYOmZd5++23mzp1La2srkyZNoquri4MHDzJ16lTuvvtuFi9ezOuvv87s2bPp7Ozk97//PX/605948sknWbx48YhqzkS3vItI8Vm7NjmnPXi6JAefeU2fPp1Vq1Zx8803M3bsWG688UYGP/RlzZo1zJ07l+rqambOnMnx48cBuO++++js7MTdaWpqoq6ujvXr17Nx40YSiQRXXnkl999/P+PGjeORRx5h0aJFnD59mjvvvJPp06ePqOZMLNOczEg1NDS4HqQgIoMdOHCA2tra6D/Q1pac037nneRIe+3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vS0mV0dd00pDwF/BXw0xP6C9FeEuqAw/eXAr8xst5m1ZNh/pr9SulPbCl0XwLzUdN0LZjY95nqmAj3A36Wmux4zs9K0NoXoqyh1QX77Kt0y4IkM22Pvr4IFt7ufdvd6oBKYY2Yz0ppkGi3GPvqNUNdzQI273wD8bz4e5cbGzL4EvOvuu8/VLMO2WPsrYl1576+U+e4+i+SvrXeZ2YK0/QX5+8Xwdb1K8tbnOuB/AltirmccMAv4W3e/Efh/wH9La1OIvopSV7776ozU1M1iINPDXmPvr4JfVZL69edF4Atpu7qBqwHMbBxwGfB+oety9153/2Pq20eBm/JQznxgsZkdAp4EPmdmG9PaFKK/hq2rQP2Fu/8h9fouyTnIOWlNzvRXSiXwh0LX5e7HBqbr3P15IGFmk2IsqRvoHvSb5dMkAzO9Tb77ati6CtBXg30ReNXdj2bYF3t/FeqqknIzuzz1/mLg88Cbac22Anek3t8G7PCYLzqPUlfaXNVikh/Kxcrd/9rdK929huSvZzvc/WtpzfLeX1HqKkR/mVmpmV0y8B74M2BfWrOtwIrUFQCfAfrc/Z8KXZeZXTnw2YSZzSH5b7Q3rprc/Z+BLjO7PrWpCdif1izvfRWlrnz3VZrbyTxNAnnor0JdVTIZ+EnqU9kxwCZ3/4WZtQLt7r6V5IcSPzOz35EcOS4rkrruNrPFwIepulbmoa6MiqC/otRViP6qAJ5N/ZseB/y9u283s/8E4O4/Ap4HbgV+B5wEvlEkdd0G/Gcz+xD4V2BZ3P8DBv4SaEv9+n8Q+EYR9FWUugrRV5hZCXAL8BeDtuW1v3TnpIhIYAo+xy0iItlRcIuIBEbBLSISGAW3iEhgFNwiIoFRcIuIBEbBLSISGAW3iEhg/j93a8xuZTm2VQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(data[label_3 == 0][:, 0], data[label_3 == 0][:, 1], c=\"red\", marker='o', label='class0')  # 以红色圆圈样式绘制散点图并加上标签\n",
    "plt.scatter(data[label_3 == 1][:, 0], data[label_3 == 1][:, 1], c=\"green\", marker='*', label='class1')  # 以绿色星星样式绘制散点图并加上标签\n",
    "plt.scatter(data[label_3 == 2][:, 0], data[label_3 == 2][:, 1], c=\"blue\", marker='+', label='class2')  # 以蓝色加号样式绘制散点图并加上标签\n",
    "plt.legend()  # 设置图例"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 13.1.3 案例实战 - 银行客户分群模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>年龄(岁)</th>\n",
       "      <th>收入(万元)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50</td>\n",
       "      <td>66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>44</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>30</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>46</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>32</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   年龄(岁)  收入(万元)\n",
       "0     50      66\n",
       "1     44      51\n",
       "2     30      56\n",
       "3     46      50\n",
       "4     32      50"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd \n",
    "data = pd.read_excel('客户信息.xlsx')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.可视化展示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3X2UXVWZ5/HvQ1VeMNGESFkdwVAB0kqIilJhNPQ4vEijQgcaAosEJGuGWcys1fFlyQpiz6KHJMjIMK30ArQbAY0zVMgbL1m+YkcZe2QBCYgCoUOwLcJrCJAEaCEhlWf+uKfohFTVPbdqn7v3uef3WatW6t46de+z6xT1cJ797H3M3RERkeo6IHYAIiISlxKBiEjFKRGIiFScEoGISMUpEYiIVJwSgYhIxSkRiIhUnBKBiEjFKRGIiFRce+wA8jj44IO9q6srdhgiIqXy4IMPvuTuHfWOK0Ui6OrqYv369bHDEBEpFTN7Ks9xKg2JiFScEoGISMUpEYiIVJwSgYhIxSkRiIhUnBKBiEggO97cwdE3HM2ON3fEDqUhSgQiIoH8aNOP2PDSBn686cexQ2mIEoGIyAjNWz2P8VeNZ/6d8wG48M4LGX/VeOatnhc5snyUCERERmjxiYuZMmEKow4YBcCoA0Zx2MTDWHLiksiR5aNEICKVFaqmf+SkI1l84mLe2vMW40aN4609b7HohEUcMemI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8F/ihJfLZGCpmbVR+5+IFe7+QzPbANxmZlcCv6GW8FI12Bh+YWYd1EosDwP/NWaQw/RVynMeBnNric5DJ3BHLWfRDvS4+0/NbB3l+bsEaGWxiEjllaI0JCIixVEiEBGpOCUCEZGKUyIQEak4JQIRkYpTIhARqTglAhGRilMiEKnDzO7MNhV7rH9jMTO7yMyeMLN7zOy7ZnZ99nyHma02s3XZx/FxoxepTwvKROows0nu/kq2JcU64FTg18DHgdeAXwC/dfcFZtYDfNvd/5+ZTQF+lt2DQiRZZdliQiSmL5rZX2aff4DaViH/191fATCzlcCfZl//NDA923YA4D1m9u7sHhQiSVIiEBmCmZ1A7Y/7J939j2Z2D7CRgbffhlq59ZPu/kZzIhQZOc0RiAxtArAtSwIforbt9ruA/2BmB2XbPp+91/F3Awv6H6R+z10RUCIQqeenQLuZ/Q5YAtwHPAtcRe0Oc/8IbAB2ZMd/EejO7rC1gbR3zxQBNFksMixmNt7dX8+uCO4AbnH3O2LHJTIcuiIQGZ4rsvtKPAr8Abgzcjwiw6YrAhGRitMVgYhIxSkRiIhUnBJ1tMpzAAAAG0lEQVSBiEjFKRGIiFScEoGISMUpEYiIVNz/B7SS9yxzXPyOAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(data.iloc[:, 0], data.iloc[:, 1], c=\"green\", marker='*')  # 以绿色星星样式绘制散点图\n",
    "plt.xlabel('age')  # 添加x轴名称\n",
    "plt.ylabel('salary')  # 添加y轴名称\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.数据建模"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "kms = KMeans(n_clusters=3, random_state=123)\n",
    "kms.fit(data)\n",
    "label = kms.labels_\n",
    "label = kms.fit_predict(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 2 2 2 0 2\n",
      " 1 2 0 1 1 2 1 2 1 2 1 1 2 2 0 1 2 1 1 1 1 2 1 2 2 2 2 0 0 0 0 0 0 0 0 0 0\n",
      " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 1 1 1 2 1 2 0 0 0 0 0 0\n",
      " 2]\n"
     ]
    }
   ],
   "source": [
    "print(label)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.建模效果可视化展示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1b24d891160>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3WuUFfW55/HvAzQCoiKILaaFhkgUuaqoUU+4SDwmJkMMGIN4wegKM2uFo1nJ4sQcT7yguHSMRqOZOF6SkNBeEGLs5CQaR8TMmJNIG8FwkaCxgTZekJtwEITmmRe7Ghtoumt3V+2q2vX7rFVr966uXfupXbCfrud/KXN3REQkvzolHYCIiCRLiUBEJOeUCEREck6JQEQk55QIRERyTolARCTnlAhERHJOiUBEJOeUCEREcq5L0gGEcdRRR3l1dXXSYYi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euCETa58bgvhLLgDeBXyUcj0i76YpARCTndEUgIpJzSgQiIjmnRCAiknNKBCIiOadEICKSc0oEIiI59/8Bjr7cUMAXI8YAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(data[label == 0].iloc[:, 0], data[label == 0].iloc[:, 1], c=\"red\", marker='o', label='class0')  # 以红色圆圈样式绘制散点图并加上标签  \n",
    "plt.scatter(data[label == 1].iloc[:, 0], data[label == 1].iloc[:, 1], c=\"green\", marker='*', label='class1')  # 以绿色星星样式绘制散点图并加上标签 \n",
    "plt.scatter(data[label == 2].iloc[:, 0], data[label == 2].iloc[:, 1], c=\"blue\", marker='+', label='class2')  # 以蓝色加号样式绘制散点图并加上标签\n",
    "plt.xlabel('age')  # 添加x轴名称\n",
    "plt.ylabel('salary')  # 添加y轴名称\n",
    "plt.legend()  # 设置图例"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.补充知识点，查看各标签人的收入均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21.125\n",
      "57.55555555555556\n",
      "46.285714285714285\n"
     ]
    }
   ],
   "source": [
    "print(data[label == 0].iloc[:, 1].mean())  # 看下分类为标签0的人的收入均值，iloc[:, 1]为data表格的第二列，也即“收入”列\n",
    "print(data[label == 1].iloc[:, 1].mean())\n",
    "print(data[label == 2].iloc[:, 1].mean())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
